package com.woniuxy.service.impl;

import com.woniuxy.dao.StudentAdministrationDao;
import com.woniuxy.dao.UsersDao;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Skill;
import com.woniuxy.entity.Training;
import com.woniuxy.entity.User;
import com.woniuxy.entity.dto.StudentDto;
import com.woniuxy.entity.dto.UserRoleDto;
import com.woniuxy.service.StudentAdministrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author：jojo
 * @Date：2022/3/11 17:12
 * @Description :TODO
 */
@Service
public class StudentAdministrationServiceImpl implements StudentAdministrationService {

    @Autowired(required = false)
    StudentAdministrationDao studentAdministrationDao;

    @Override
    public ResponseEntity findAll() {
        List<Integer> ids = studentAdministrationDao.findIds();
        List<StudentDto> list = new ArrayList();
        for (Integer id:ids){
            StudentDto studentDto = new StudentDto();
            User user = studentAdministrationDao.findUser(id);
            studentDto.setUser(user);
            String role = studentAdministrationDao.findRole(id);
            studentDto.setRole(role);
            int countTraining = studentAdministrationDao.findCountT(id);
            studentDto.setCountTraining(countTraining);
            int countCourse = studentAdministrationDao.findC(id);
            studentDto.setCountCourse(countCourse);
            int nowT = studentAdministrationDao.findNT(id);
            studentDto.setNowTraining(nowT);
            int nowC = studentAdministrationDao.findNC(id);
            studentDto.setNowCourse(nowC);
            List<String> studyTime = studentAdministrationDao.findTime(id);
            int times = 0;
            for (String time:studyTime){
                times+=Integer.parseInt(time);
            }
            studentDto.setStudyTime(times);
            list.add(studentDto);
        }
        return ResponseEntity.success("查询成功",list);
    }

    @Override
    public ResponseEntity findOneUser(int id) {
        UserRoleDto userRoleDto = new UserRoleDto();
        User user = studentAdministrationDao.findOneUser(id);
        String role = studentAdministrationDao.findOneRole(id);
        userRoleDto.setUser(user);
        userRoleDto.setRole(role);
        return ResponseEntity.success("success",userRoleDto);
    }

    @Override
    public ResponseEntity findSkill(int id) {
        Skill skill = studentAdministrationDao.findSkill(id);
        return ResponseEntity.success("success",skill);
    }

    @Override
    public ResponseEntity findSearch(int id, String trainingname) {
        List<Training> training = studentAdministrationDao.findSearch(id,trainingname);
        if (training.size() > 0){
            return ResponseEntity.success("有",training);
        }else{
            return ResponseEntity.success("没有",null);
        }
    }
}
